﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SchoolArea.aspx.cs" Inherits="Education_SchoolArea" %>

<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>学区管理</title>
    
    <link href="../Common/css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
        #load{width:500px;height:25px;border:1px #000 solid;}
        #loading{position:absolute;z-index:2;height:23;filter:progid:DXImageTransform.microsoft.gradient(gradienttype=1,startColorStr=white,endColorStr=#39867b);}
        #loadtext{position:absolute;z-index:3;width:100%;height:100%;line-height:23px;text-align:center;}
    </style>
    
    <script type="text/javascript" src="../Common/Js/jquery.js"></script>

    <script type="text/javascript" src="../Common/Js/common.js"></script>

    <script type="text/javascript" src="../Common/Js/msg.js"></script>

    <script type="text/javascript" src="../Common/Js/jsUtil.js"></script>
    
    <script type="text/javascript">
    
var optionType = '';
var editSchoolAreaId = 0;
    
function Load()
{
    Bind(0,"");
}

function Bind(queryType,queryValue)
{
    if (queryType == 0)
    {
        document.getElementById('queryType').value = "0";
        document.getElementById('queryKeyWord').value = "";
        document.getElementById('queryKeyWord').disabled = true;
    }

    //查询条件
    document.getElementById('HFQueryType').value = queryType;
    document.getElementById('HFQueryValue').value = queryValue;
    document.getElementById('btnBind').click();
}

function ShowAddWindow()
{
    optionType = 'add';

    ShowPopForm("popTable", "formTitle", "新增", "");
    showMask();
}

function ShowUpdateWindow(obj)
{
    optionType = 'update';

    ShowPopForm("popTable", "formTitle", "修改", "");
    showMask();
    
    editSchoolAreaId = obj.id;

    PageMethods.SelectSohoolArea(editSchoolAreaId,function(succ){
        if(succ != null)
        {
            document.getElementById('areamark').value = succ.SchoolAreaMark;
            document.getElementById('areamark').setAttribute("oldMark",succ.SchoolAreaMark);
            document.getElementById('areaname').value = succ.SchoolAreaName;
            document.getElementById('areaname').setAttribute("oldName",succ.SchoolAreaName);
        }

    },function(err){//异步失败
        showMassgeBox("提示","获取学区信息失败，请刷新重试",1,null);
    });
}

//删除学区信息
function DelSchoolAreaInfo(obj)
{
    var areaId = obj.id;

    showConfirmBox("删除", "此操作会删除学区信息，确定删除?", delSchoolAreaInfo, areaId);
}

function delSchoolAreaInfo(obj)
{
    PageMethods.ValidateDelete(obj,function(succ){
        if (succ > 0)
        {
            if (succ == 1)
            {
                showMassgeBox("提示","该学区中存在学校，不能删除",1,null);
            }
        }
        else
        {
            PageMethods.DeleteSchoolArea(obj,function(succ){
                if (succ > 0)
                {
                    Bind(0,"");
                    showMassgeBox("提示","学区删除成功",1,null);
                }
                else
                {
                    showMassgeBox("提示","学区删除失败",1,null);
                }
            },function(err){
                showMassgeBox("提示","学区删除失败，您可以刷新后重试",1,null);
            });        
        }
    },function(err){
        showMassgeBox("提示","学区删除失败，您可以刷新后重试",1,null);
    });
}

function CloseMask(formId)
{
    ReleasePopTable();
    ClosePopForm(formId,true);
    hideMask();
}

//添加或更新操作成功后清空内容
function ReleasePopTable()
{
    document.getElementById('areamark').value = "";
    document.getElementById('areaname').value = ""
}


function Add(areaMark,areaName)
{
    var schoolArea = {RID:0,SchoolAreaMark:areaMark,SchoolAreaName:areaName};
    
    PageMethods.ValidateAreaInfo(schoolArea,function(succ){ 
       if(succ > 0)
       {
            if (succ == 1)
            {
                showNoticMsg('areamark','已经存在此学区编号，请重新设置');
                document.getElementById('areamark').select();  
            }
            if (succ == 2)
            {
                showNoticMsg('areaname','已经存在此学区名称，请重新设置');
                document.getElementById('areaname').select();              
            }
       }
       else
       {  
            PageMethods.InsertSchoolAreaInfo(schoolArea,function(succ){
                if(succ > 0)
                {
                    Bind(0,"");
                    CloseMask('popTable');
                }
                else
                {
                    showMassgeBox("提示","学区添加失败",1,null);
                }
            },function(err){
                showMassgeBox("提示","学区添加失败",1,null);
            }); 
       }      
    },function(err){
            showMassgeBox("提示","学区验证过程失败，您可以刷新后重试",1,null);
    });
}

function Update(areaID,areaMark,areaName)
{
    var schoolArea = {RID:areaID,SchoolAreaMark:areaMark,SchoolAreaName:areaName};
    
    var oldMark = document.getElementById('areamark').getAttribute("oldMark");
    var oldName = document.getElementById('areaname').getAttribute("oldName");
    //判断学区编号或学区名称是否修改，先验证后更新
    if ( (oldMark != areaMark) || (oldName != areaName) )
    {
        PageMethods.ValidateAreaInfo(schoolArea,function(succ){ 
           if(succ > 0)
           {
            if (succ == 1)
            {
                showNoticMsg('areamark','已经存在此学区编号，请重新设置');
                document.getElementById('areamark').select();  
            }
            if (succ == 2)
            {
                showNoticMsg('areaname','已经存在此学区名称，请重新设置');
                document.getElementById('areaname').select();              
            }
           }
           else
           {  
                PageMethods.UpdateSchoolAreaInfo(schoolArea,function(succ){
                    if(succ > 0)
                    {
                        Bind(0,"");
                        CloseMask('popTable');
                    }
                    else
                    {
                        showMassgeBox("提示","学区添加失败",1,null);
                    }
                },function(err){
                    showMassgeBox("提示","学区添加失败",1,null);
                }); 
           }
        },function(err){
             showMassgeBox("提示","学区验证过程失败，您可以刷新后重试",1,null);
        });
    }
    //没有修改的情况直接更新
    else
    {
        PageMethods.UpdateSchoolAreaInfo(schoolArea,function(succ){
            if(succ > 0)
            {
                Bind(0,"");
                CloseMask('popTable');
            }
            else
            {
                showMassgeBox("提示","学区添加失败",1,null);
            }
        },function(err){
            showMassgeBox("提示","学区添加失败",1,null);
        }); 
    }
}

function Save()
{ 
    var areaMark = document.getElementById('areamark').value.Trim();
    var areaName = document.getElementById('areaname').value.Trim();
    
      //判断学区标识是否为空
    if (areaMark == "")
    {
        showNoticMsg('areamark','学区编号不能为空，请重新输入');
        document.getElementById('areamark').select();  
        return;  
    }
    
    //判断学区名称是否为空
    if (areaName == "")
    {
        showNoticMsg('areaname','学区名称不能为空，请重新输入');
        document.getElementById('areaname').select();  
        return;  
    }
    
    //判断学区标识是否大于6个字符
    if (getStringCount(areaMark) > 6)
    {
        showNoticMsg('areamark','学区编号教不能超过六个字符，请重新输入');
        document.getElementById('areamark').select();  
        return; 
    }
    
    if (containSpecialChar(areaMark) == true)
    {
        showNoticMsg('areaMark','学区编号不能包含特殊字符，请重新输入');
        document.getElementById('areamark').select();  
        return;
    }
    
    if (containSpecialChar(areaName) == true)
    {
        showNoticMsg('areaname','学区名称不能包含特殊字符，请重新输入');
        document.getElementById('areaname').select();  
        return;
    }
    
        
    if(optionType == "add")
    {
       Add(areaMark,areaName);
    }
    if(optionType == "update")
    {
       Update(editSchoolAreaId,areaMark,areaName);
    }
}

function QueryArea()
{
    var qType = document.getElementById('queryType').value;
    var qKeyWord = document.getElementById('queryKeyWord').value.Trim();
    
    if (containSpecialChar(qKeyWord))
    {
        showNoticMsg('queryKeyWord',"查询内容不能包含特殊字符",-150);
        return;
    }

    Bind(qType,qKeyWord);
}

function submitQuery()
{
    if(event.keyCode==13)     
    {     
        event.keyCode=9;   
        event.returnValue = false;
        document.getElementById('btnquery').click();     
    }   
}

function queryType_Change(obj)
{
    if (obj.value == "0")
        document.getElementById('queryKeyWord').disabled = true;
    if (obj.value == "1")
        document.getElementById('queryKeyWord').disabled = false;
    if (obj.value == "2")
        document.getElementById('queryKeyWord').disabled = false;
        
    document.getElementById('queryKeyWord').value = "";
}

function SetHightLight(obj)
{
     obj.style.backgroundColor = "#fffccf";
     var table = document.getElementById('schoolAreaTable');
     for(var i =0 ; i < table.rows.length;i++)
     {
        var row = table.rows[i];
        if(row != null && row.id != obj.id)
            row.style.backgroundColor = "#ffffff";
        
     }
}

    </script>
    

</head>
<body onload="Load();">
    <div class="mainWarp">
        <div class="pageBody">
            <form id="form1" runat="server">
                <div>
                    <ul class="butList">
                        <li>
                        <table width="100%" border="0">
                            <tr>
                               <td  width= "40%" style ="text-align: left;">
                                    <input type="button" id="button3" value="新增" onclick="ShowAddWindow();" class="commonBut" />
                               </td>
                               <td width= "60%" style ="text-align: right;">
                                   查询方式:<select id="queryType" style="width: 120px" onchange="queryType_Change(this);">
                                        <option value="0" selected>所有</option>
                                        <option value="1">学区编号</option>
                                        <option value="2">学区名称</option>
                                    </select>
                                    <input type="text" id="queryKeyWord" onkeydown="submitQuery();" class="txtStyle"
                                        style="width: 120px" />
                                    <input id="btnquery" class="commonBut" onclick="QueryArea();" type="button" value="查询" />
                               </td>
                            </tr>
                        </table>
                        
                        </li>
                    </ul>
                </div>
                <div>
                    <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
                    </asp:ScriptManager>
                </div>
                <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:Repeater ID="Repeater1" runat="server">
                            <HeaderTemplate>
                                <table id="schoolAreaTable" border="0" cellpadding="0" cellspacing="1" class="useList">
                                    <tr class="tableTitle">
                                        <th width="20%" style="text-align: left;padding-left:5px;">
                                            学区编号</th>
                                        <th width="50%" style="text-align: left;padding-left:5px;">
                                            学区名称</th>
                                        <th width="30%">
                                        </th>
                                    </tr>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr id="<%# DataBinder.Eval(Container.DataItem, "RID") %>" 
                                    style="background-color: White;"  onclick="SetHightLight(this);">
                                    <td style="text-align: left; font-weight: normal;padding-left:5px;">
                                        <%# DataBinder.Eval(Container.DataItem, "SchoolAreaMark")%>
                                    </td>
                                    <td style="text-align: left; font-weight: normal;padding-left:5px;">
                                        <%# DataBinder.Eval(Container.DataItem, "SchoolAreaName")%>
                                    </td>
                                    <td>
                                        <img src="../common/images/hadle_icon.gif" alt="修改学区信息" class="imageBtnStyle" onclick="ShowUpdateWindow(this.parentElement.parentElement)" />
                                        <img src="../common/images/delete_icon.gif" alt="删除学区信息" class="imageBtnStyle" onclick="DelSchoolAreaInfo(this.parentElement.parentElement);" />
                                    </td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </table>
                            </FooterTemplate>
                        </asp:Repeater>
                         <webdiyer:aspnetpager id="AspNetPager1" runat="server" horizontalalign="Right"  PageSize="15" 
                            width="100%"   PagingButtonSpacing="10px" ButtonImageAlign="left" 
                            OnPageChanged="AspNetPager1_PageChanged"> </webdiyer:aspnetpager> 
                        </td> </tr> </table>
                    </ContentTemplate>
                    <Triggers>
                        <asp:AsyncPostBackTrigger ControlID="btnBind" EventName="Click" />
                    </Triggers>
                </asp:UpdatePanel>
                <div style="display: none;">
                    <asp:Button ID="btnBind" runat="server" OnClick="btnBind_Click" Text="btnBind" />
                    <asp:HiddenField ID="HFQueryType" runat="server" Value="" />
                    <asp:HiddenField ID="HFQueryValue" runat="server" Value="" />
                </div>
            </form>
            <!-- 新增/修改学区弹出界面 开始-->
            <div id="popTable" class="layoutWarp" style="display: none; width: 400px; overflow: inherit;">
                <div class="title">
                    <span id="formTitle">新增</span> <a title="关闭" onclick="return CloseMask('popTable')">
                        关闭</a>
                </div>
                <table style="width: 380px; margin-top: 12px;" border="0" class="layoutTable">
                    <tr>
                        <td width="35%" valign="top" style="text-align: right">
                             学区编号:</td>
                        <td style="text-align: left; width: 243px; color:Red">
                            <input type="text" name="textfield" id="areamark" style="width: 120px" class="txtStyle" maxlength = "6" /> *</td>
                    </tr>
                    <tr>
                        <td valign="top" style="text-align: right">
                            学区名称:</td>
                        <td style="text-align: left; width: 243px; color:Red">
                            <input id="areaname" name="textfield2" style="width: 120px" class="txtStyle"  maxlength = "25" type="text" /> *</td>
                    </tr>
                    <tr>
                        <td colspan="3" align="center">
                            <ul class="butList">
                                <input type="button" id="btnsave" value="保存" onclick="Save()" class="commonBut" />
                                <input type="button" value="取消" onclick=" CloseMask('popTable');" class="commonBut" />
                            </ul>
                        </td>
                    </tr>
                </table>
            </div>
            <!-- 新增/修改学区弹出界面 结束 -->
        </div>
    </div>
</body>
</html>
